	 $(document).ready(function(){
		 $(".inline").colorbox({inline:true, width:"50%"});
	 });
	
	 $(document).ready(function(){
		 $("#postitYellow").click(function() {
			 $("#errors ul").html("");
			 $('#confessionData').val("Enter your Confession......");
		 });
		 
		  $(".submitButton").click(function(){
			  
			  	var confession = $("#confessionData").val();
			  	if (validate(confession))
			      $.ajax({
			          url: "/submitConfession/",
			          type: 'POST',
			          data: {confession: confession},
			          success: function() {
			        	  $.colorbox.close();
			        	  alertify.custom = alertify.extend("custom");
			        	  alertify.custom("Confession Created !");
			        	  updateConfessions();
			          },
			          error:function(data) {
			        	  $("#errors ul").append('<li>The confession failed to process.</li>');
				   		  console.log("error with create");
				      }	
			      });
			      return false;
		   });
		  
		  
		$('#confessionData').blur(function() {
			 if($(this).val() === "") {
				 $(this).val("Enter your Confession......");
			 }
		});
		
		$('#confessionData').focus(function() {
			  $(this).val(""); 
		});
		var page= 1;
		$(window).scroll(function() {
			   console.log($(window).scrollTop());
			   console.log($(window).height());
			   console.log($(document).height());
				   if($(window).scrollTop() + $(window).height() == $(document).height()) {
					   
					   $.ajax({
					          url: "/page/"+page,
					          type: 'GET',
					          dataType: 'text',
					          success: function(data) {
					              $("#confessions").append(data);
					              $contentLoadTriggered = false;
					              page = page + 1;
					          },
					   		  error:function(data) {
					   			console.log("error with infinite");
					   		  }	
				  });
			   }
		});	   

	 });
	 
	 function validate(confession) {
		 $("#errors ul").html("");
		 if('null' == confession || confession.length > 125
				 || confession == "Enter your Confession......") {
			 $("#errors ul").append('<li>The confession is invalid.</li>');
		  	$("#errors ul").hide().fadeIn(1200);
			 return false
		 }
		 
		  var re = new RegExp(/[\<\>\[\]\(\)="\/\?@\;]/g); 
		  
		  	if (re.test(confession)) {
		  		$("#errors ul").append('<li>The confession contains invalid characters.</li>');
		  		$("#errors ul").hide().fadeIn(1200);
		  		return false
		  	} 
		 
		 return true
	 }
	 
	 window.setInterval(updateConfessions, 10000);
	 function updateConfessions() {
		 var div = document.getElementById('confessions');
		   $.ajax({
		          url: "/updateConfessions/",
		          type: 'GET',
		          dataType: 'text',
		          success: function(data) {
		        	  console.log(data);
		        	  $("#confessions").prepend(data);
		        	  $("#newConfession").hide().fadeIn(1200);
		        	  $("#newConfession").attr("id","");
		          },
		   		error: function(data) {
		   			console.log(data);
		   		}
		  });
	 }
	 

	 